<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateTablePosts extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('user_id')->comment('发帖人用户ID');;
            $table->string('user_name')->comment('发帖人用户名');
            $table->string('last_reply_name')->nullable()->default()->comment('最后回复人用户名');;
            $table->unsignedInteger('comments')->nullable()->default(0)->comment('当前帖子被回复次数');;
            $table->string('title')->comment('标题');;
            $table->text('content')->comment('内容');;
            $table->timestamps();

            $table->foreign('user_id')->references('id')->on('users');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('posts');
    }
}
